package org.madgecko.api.dao.impl;

import org.madgecko.api.dao.iface.IMessageDao;
import org.madgecko.api.model.Message;
import org.madgecko.api.model.enumeration.MessageCategory;
import org.madgecko.basic.dao.BaseDao;
import org.madgecko.basic.model.Pager;
import org.madgecko.basic.kit.BasicKit;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Author       : MadFrog
 * Date         : 2018/11/10 17:55
 * Description  : 消息数据访问接口
 */
@Repository
public class MessageDao extends BaseDao<Message> implements IMessageDao {
    @Override
    public List<Message> listByCategory(MessageCategory messageCategory) {
        String hql = "from Message where category=" + messageCategory.ordinal() + " order by createDate desc";
        return this.list(hql);
    }

    @Override
    public Pager<Message> find(MessageCategory messageCategory) {
        String hql = "from Message m where 1=1 ";
        if (messageCategory!=null){
            hql += " and m.category=" + messageCategory.ordinal();
        }
        hql += " order by createDate desc";
        return this.find(hql);
    }
}
